<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <!-- 第一个页签 -->
          <el-tab-pane label="角色管理">
            <el-row>
              <el-button type="primary" size="small" @click="showDialog=true">新增角色</el-button>
            </el-row>
            <!-- 表格 -->
            <el-table :data="list" stripe border style="width:100%;margin-top:50px">
              <el-table-column align="center" label="序号" width="120" type="index" />
              <el-table-column align="center" label="名称" width="240" prop="name" />
              <el-table-column align="center" label="描述" prop="description" />
              <el-table-column align="center" label="操作">
                <template slot-scope="obj">
                  <el-button type="success" size="mini">分配权限</el-button>
                  <el-button type="primary" size="mini" @click="editRole(obj.row.id)">编辑</el-button>
                  <el-button type="danger" size="mini" @click="deleteRole(obj.row.id)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
            <!-- 分页器 -->
            <el-row type="flex" justify="center" align="middle" style="height:60px">
              <el-pagination layout="prev, pager, next" :total="page.total" :page-size="page.pagesize" :current-page="page.page" @current-change="changePage" />
            </el-row>
            <!--
            <el-row>
              <el-pagination
                layout="prev, pager, next"
                :total="90"
              />
            </el-row> -->
            <!-- <el-row>
              <el-pagination layout="prev, pager, next" :total="90" :page-size="3" />
            </el-row> -->
            <!-- <el-row type="flex" justify="center" align="middle" style="height:60px">
              <el-pagination layout="prev, pager, next" :total="total" :page-size="pagesize" :current-page="page" @current-change="changePage" />
            </el-row> -->

          </el-tab-pane>
          <!-- 第二个页签 -->
          <el-tab-pane label="公司信息">
            <el-alert
              title="对公司名称、公司地址、营业执照、公司地区的更新，将使得公司资料被重新审核，请谨慎修改"
              type="info"
              show-icon
            />
            <!-- 表单信息 -->
            <el-form label-width="120px" disabled style="margin-top:50px">
              <el-form-item label="公司名称">
                <el-input v-model="FormData.name" style="width:400px" />
              </el-form-item>
              <el-form-item label="公司地址">
                <el-input v-model="FormData.companyAddress" style="width:400px" />
              </el-form-item>
              <el-form-item label="邮箱">
                <el-input v-model="FormData.mailbox" style="width:400px" />
              </el-form-item>
              <el-form-item label="备注">
                <el-input v-model="FormData.remarks" type="textarea" style="width:400px" />
              </el-form-item>
            </el-form>
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </div>

    <addDialog ref="addDia" :is-show-dia="showDialog" :show-dialogedit.sync="showDialog" :add-dialog="getRoleList" />
  </div>
</template>

<script>
import { getRoleList, delRole, getCompanyInfo } from '@/api/setting'
import { mapGetters } from 'vuex'
import addDialog from './components/add-dialog.vue'
export default {
  components: {
    addDialog
  },
  data() {
    return {
      page: {
        page: 1, // 当前第几页，默认第一页
        pagesize: 10, //
        total: 0// 总角色数量
      },
      // page: 1,
      // pagesize: 3,
      // total: 0,
      list: [], // 角色列表
      FormData: {}, // 公司信息
      showDialog: false// 默认编辑弹窗关闭
    }
  },
  computed: {
    ...mapGetters['companyId']
  },
  created() {
    this.getRoleList()
    this.getCompanyInfo()
  },
  methods: {
    async getRoleList() {
      const res = await getRoleList(this.page)
      console.log(res, '@@@@')
      // console.log(this.page, '111111111111111')
      // console.log(this.page.pagesize, '2222222222222')
      this.list = res.rows
      this.page.total = res.total
      // this.total = res.total
      // console.log(this.list, this.page.total, '&&&&&&77')
    },
    changePage(currentP) {
      this.page.page = currentP
      // this.page = currentP
      // debugger
      this.getRoleList()
    },
    // 删除角色
    async deleteRole(id) {
      // console.log(id)
      try {
        await this.$confirm('是否确定删除该角色', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' })
        this.$message({ type: 'success', message: '删除成功！' })
        // 调用删除接口
        await delRole(id)
        // 再次获取新的角色列表
        this.getRoleList()
      } catch (error) {
        this.$message({ type: 'info', message: '已取消删除操作' })
      }
    },
    // 查询公司信息
    async getCompanyInfo() {
      this.FormData = await getCompanyInfo(this.companyId)
      console.log(this.FormData)
    },
    // 点击编辑按钮
    async editRole(id) {
      this.$refs.addDia.getRoleDetail(id)
      this.showDialog = true
    }
  }
}
</script>

  <style>

  </style>

